package io.gitee.caoxiaoyu97.log.sensitive.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author caoxiaoyu
 */

public enum KeywordExpEnum {
	
	/**
     * 真实姓名
     */
    TRUE_NAME("^[\\p{IsHan}]{2,4}$",KeywordTypeEnum.TRUE_NAME),
    /**
     * 身份证号码
     */
    ID_CARD_NO("^[1-9]\\d{5}((19[2-9]\\d)|20[0-1]\\d)((0[1-9])|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X|x)$",
    		KeywordTypeEnum.ID_CARD_NO),
    /**
     * 银行卡号
     */
    BANKCARD_NO("^([1-9]{1})(\\d{15,18})$",KeywordTypeEnum.BANKCARD_NO),
    /**
     * 手机号码
     */
    PHONE_NO("\\b(1[3-9][0-9]\\d{8})\\b",KeywordTypeEnum.PHONE_NO),
    
    /**
     * 邮箱
     */
    MAIL("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",KeywordTypeEnum.OTHER),
    		
    /**
     * 其它
     */
    OTHER("",KeywordTypeEnum.OTHER){
    	public boolean isAvailable() {
    		return false;
    	}
    };

	
	private Pattern regPattern;
	private KeywordTypeEnum operation;
	
	KeywordExpEnum(String regExp,KeywordTypeEnum operation) {
		this.operation = operation;
		try {
			regPattern = Pattern.compile(regExp);
		} catch (Exception ignored) {

		}
	}
	
	public Matcher getMatcher(String content) {
		return regPattern.matcher(content);
	}
	
	public String getKeywordType() {
		return this.operation.getKeywordType();
	}
	
	public boolean isAvailable(){
		return true;
	}
	
	
	
	
}
